package com.hp.his.basic.dao;

import java.util.List;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import com.hp.his.basic.entity.UPMSPage;
import com.hp.his.core.orm.Page;
import com.hp.his.core.orm.hibernate.HibernateDao;

/**
 * 基础数据字典的DAO
 * @author xuxians
 */
@Repository
public class UPMSPageDao extends HibernateDao<UPMSPage, Long>{

	/**
	 * 按术语名称及上级分类分页查询.
	 * 
	 * @param page - 分页参数.
	 * @param dictName - 字典术语.
	 * @param parentId - 上级分类ID.
	 * 
	 * @return 分页查询结果.附带结果列表及所有查询输入参数.
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Page<UPMSPage> getAll(final Page<UPMSPage> page){
		String hql = "from UPMSPage";
		Query q = createQuery(hql);
		if (page.isAutoCount()) {
			long totalCount = countHqlResult(hql);
			page.setTotalCount(totalCount);
		}
		setPageParameterToQuery(q, page);
		List result = q.list();
		page.setResult(result);
		
		return page;
	}	
//	public Page<UPMSPage> findDictsByPage(Page<UPMSPage> page, String dictName, Long parentId) {
//		Criteria c = getSession().createCriteria(entityClass);
//		if (StringUtils.isNotBlank(dictName)) {
//			c = c.add(Restrictions.like("term", dictName, MatchMode.ANYWHERE));
//		}
//		if (null != parentId && parentId.intValue() > 0) {
//			c = c.createAlias("parent", "p").add(Restrictions.eq("p.id", parentId));
//		}
//
//		if (page.isAutoCount()) {
//			long totalCount = countCriteriaResult(c);
//			page.setTotalCount(totalCount);
//		}
//
//		setPageParameterToCriteria(c, page);
//
//		List result = c.list();
//		page.setResult(result);
//		return page;
//	}
	@SuppressWarnings({ "rawtypes" })
	public UPMSPage getPageByID(Integer id){
		//定义查询语句
		String hql = "from UPMSPage where id="+id;
		Query query = getSession().createQuery(hql);
		
		List list = query.list();
		UPMSPage entity = (UPMSPage)list.get(0);
		
		return entity;
	}	
	
	@SuppressWarnings({ "rawtypes" })
	public UPMSPage getPageByPageID(String pageId){
		//定义查询语句
		String hql = "from UPMSPage where pageId='"+pageId+"'";
		Query query = getSession().createQuery(hql);
		
		List list = query.list();
		UPMSPage entity = (UPMSPage)list.get(0);
		
		return entity;
	}	
}
